/**
 * 质控现场考核管理模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.qc.localeCheck.localeCheckManager',['water.entity.localeCheck']);
	
	module.controller('localeCheckManagerController',function($rootScope,$scope,$localeCheckService){


		/**
		 * 采样详情对话框对象
		 */
		$scope.samplingDetailDialog;
		/**
		 * 质量详情对话框对象
		 */
		$scope.massControlDetailDialog;
		/**
		 * 运维考核详情对话框对象
		 */
		$scope.operateDetailDialog;
		/**
		 * 采样(敏感点空气)详情对话框对象
		 */
		$scope.samplingFlueGasDetailDialog;
		/**
		 * 考核详情
		 */
		$scope.DetailDialog;
		/**
		 * 页面条件集
		 */
		$scope.queryObject={};
		/**
		 * 站点查询参数，为true时，查询所有站点现场考核信息
		 * 为false时，根据站点查询现场考核信息
		 * 默认为true
		 */
		$scope.allStationSelected =true;
		/**
		 * 用于控制详情页面跨行
		 */
		$scope.name="";
		/**
		 * 考核选项
		 */
		$scope.checkOption=[{v:"全部",k:"all"},{v:"实验室现场检查",k:"101"},{v:"采样现场检查",k:"102"},{v:"运营维护检查",k:"103"}];
		/**
		 * 考核选项
		 * 默认选项全部
		 */
		$scope.checkOptionModel="all";
		/**
		 * 详情按钮点击事件
		 */
		$scope.onDetailClick = function(data){			
			_getDetailList(data);
		}
		
		$scope.firstQuery = true;
		/**
		 * 查询按钮单击事件
		 */
		$scope.ongetListClick=function(){
			_getList();
		}
		/**
		 * 监听站点列表点击事件
		 */
		$scope.dataPramChangedBroadCast = $scope.$on('dataPramChanged', function(event, data) {
			
			$scope.STATIONID=data.data.POINTCODE;
			if($scope.firstQuery){
				$scope.allStationSelected = true;
			}else{
				$scope.allStationSelected = false;
			}
			$scope.firstQuery = false;
			_getList();
	    });
		/**
		 * 页面字段显示值判断
		 */
		$scope.fieldShowPublic=function(object){
			if(object=="0"){
				return "否"
			}else if(object=="1"){
				return "是"
			}else if(object=="2"){
				return "部分存在问题"
			}
		}
		$scope.TableRow=function(FATHERNAME){			
			if($scope.name==""){
				$scope.name=FATHERNAME;
				return $scope.name;
			}else if($scope.name==FATHERNAME){
				return 2;
			}else{
				$scope.name=FATHERNAME;
				return $scope.name;
			}
		}
		/**
		 * 导出
		 */
		$scope.onToExcelClick=function(data){
			var queryObject={
					GUID:data.GUID,
					CHECK_CONTENT:data.CHECK_CONTENT
					};			
			$localeCheckService.ToExcel(queryObject);
		}
		/**
		 * 获取现场考核列表
		 */
		function _getList(){
			checkErr();
			$scope.queryObject.STATIONID=$scope.STATIONID;
			if($scope.allStationSelected==true){
				delete $scope.queryObject.STATIONID;
			}
			if($scope.checkOptionModel!="all"){
				$scope.queryObject.checktype=$scope.checkOptionModel;
			}else{
				delete $scope.queryObject.checktype;
			}
			$localeCheckService.getList($scope.queryObject).then(function(d){
				$scope.locaCheckList = d;
			});
		}
		
		/**
		 * 获取考核详情
		 */
		function _getDetailList(data){
			$localeCheckService.getDetailList({GUID:data.GUID,CHECK_CONTENT:data.CHECK_CONTENT}).then(function(d){
				$scope.locaCheckDetaol = d;
				$scope.locaCheckInfo =data;
				$scope.imgList=[];
				if($scope.locaCheckInfo.PHOTO){
					var imgsInfos = $scope.locaCheckInfo.PHOTO.split("|");
					if(imgsInfos.length != 0){
						for(var i=0;i<imgsInfos.length;i++){
							imgsInfos[i] = imgsInfos[i].split(":")[0];
						}
						
						$scope.imgList = imgsInfos;
					}
				}

				$scope.DetailDialog.open();
			});				
		}
		function checkErr(){		   
		    if((new Date($scope.queryObject.start.replace(/-/g,"\/"))) > (new Date($scope.queryObject.end.replace(/-/g,"\/")))){
		    	$.messager.alert("提示","起始时间不能大于结束时间");
		      return false;
		    }		 
		  };
	});
}(window, angular));	